<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CAP理论：分布式系统的基石</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            box-shadow: 0 10px 30px rgba(240, 87, 108, 0.3);
        }
        
        .concept-card {
            background: white;
            border-radius: 16px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .concept-card:hover {
            border-color: #667eea;
            transform: translateY(-5px);
            box-shadow: 0 15px 40px rgba(102, 126, 234, 0.2);
        }
        
        .icon-wrapper {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            margin-bottom: 20px;
        }
        
        .consistency-icon {
            background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
        }
        
        .availability-icon {
            background: linear-gradient(135deg, #30cfd0 0%, #330867 100%);
        }
        
        .partition-icon {
            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
        }
        
        .timeline-item {
            position: relative;
            padding-left: 40px;
            margin-bottom: 30px;
        }
        
        .timeline-item::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 5px;
            width: 10px;
            height: 10px;
            background: #667eea;
            border-radius: 50%;
        }
        
        .timeline-item::after {
            content: '';
            position: absolute;
            left: 14px;
            top: 15px;
            width: 2px;
            height: calc(100% + 20px);
            background: #e0e0e0;
        }
        
        .timeline-item:last-child::after {
            display: none;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0.1em 0;
            font-weight: 700;
            color: #667eea;
        }
        
        .quote-box {
            position: relative;
            padding: 30px;
            background: #f8f9fa;
            border-left: 4px solid #667eea;
            margin: 30px 0;
            font-style: italic;
        }
        
        .quote-box::before {
            content: '\f10d';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            top: -10px;
            left: 20px;
            font-size: 30px;
            color: #667eea;
            opacity: 0.3;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">CAP理论</h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">分布式系统设计的基石与权衡艺术</p>
                <div class="flex justify-center space-x-8 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-check-circle mr-2"></i>
                        <span>一致性</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-server mr-2"></i>
                        <span>可用性</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-network-wired mr-2"></i>
                        <span>分区容错性</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">C</span>AP理论由计算机科学家 Eric Brewer 在 2000 年提出，它揭示了在分布式数据存储中，<strong class="text-purple-600">一致性（Consistency）</strong>、<strong class="text-blue-600">可用性（Availability）</strong> 和 <strong class="text-pink-600">分区容错性（Partition Tolerance）</strong> 这三个特性之间的权衡关系。
            </p>
            
            <div class="highlight-box mt-6">
                <p class="text-lg">
                    <i class="fas fa-lightbulb mr-2"></i>
                    简单来说，CAP理论告诉我们，在一个分布式系统中，不可能同时完全满足这三项特性。我们最多只能选择其中的两项来优化，而不得不在第三项上做出一定的让步。
                </p>
            </div>
        </div>

        <!-- CAP Visualization -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">CAP理论可视化</h2>
            <div class="mermaid">
                graph TD
                    A[CAP理论] --> B[一致性 Consistency]
                    A --> C[可用性 Availability]
                    A --> D[分区容错性 Partition Tolerance]
                    
                    B --> E[CP系统]
                    C --> F[AP系统]
                    D --> G[CA系统]
                    
                    E --> H[HBase]
                    E --> I[MongoDB]
                    F --> J[Cassandra]
                    F --> K[DynamoDB]
                    G --> L[传统RDBMS]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#fa709a,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#30cfd0,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#a8edea,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Three Elements -->
        <div class="mb-12">
            <h2 class="text-3xl font-bold mb-8 section-title">CAP理论的三要素</h2>
            <div class="grid md:grid-cols-3 gap-6">
                <!-- Consistency -->
                <div class="concept-card">
                    <div class="icon-wrapper consistency-icon">
                        <i class="fas fa-check-double text-white text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">一致性（Consistency）</h3>
                    <p class="text-gray-600 mb-4">
                        所有节点在同一时间看到相同的数据状态。一旦写操作完成，所有后续的读操作都必须返回该写操作的结果。
                    </p>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li><i class="fas fa-circle text-xs mr-2 text-purple-400"></i>强一致性</li>
                        <li><i class="fas fa-circle text-xs mr-2 text-purple-400"></i>弱一致性</li>
                        <li><i class="fas fa-circle text-xs mr-2 text-purple-400"></i>最终一致性</li>
                    </ul>
                </div>

                <!-- Availability -->
                <div class="concept-card">
                    <div class="icon-wrapper availability-icon">
                        <i class="fas fa-server text-white text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">可用性（Availability）</h3>
                    <p class="text-gray-600 mb-4">
                        系统在接收到请求时，总能返回一个响应。系统必须在合理的时间内对每个请求作出响应。
                    </p>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li><i class="fas fa-circle text-xs mr-2 text-blue-400"></i>高可用性设计</li>
                        <li><i class="fas fa-circle text-xs mr-2 text-blue-400"></i>负载均衡</li>
                        <li><i class="fas fa-circle text-xs mr-2 text-blue-400"></i>故障转移</li>
                    </ul>
                </div>

                <!-- Partition Tolerance -->
                <div class="concept-card">
                    <div class="icon-wrapper partition-icon">
                        <i class="fas fa-network-wired text-gray-700 text-2xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">分区容错性（Partition Tolerance）</h3>
                    <p class="text-gray-600 mb-4">
                        系统在面对网络分区时仍能继续运行并提供服务。即使部分节点间通信中断，系统依然能够处理请求。
                    </p>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li><i class="fas fa-circle text-xs mr-2 text-pink-400"></i>数据副本</li>
                        <li><i class="fas fa-circle text-xs mr-2 text-pink-400"></i>数据分片</li>
                        <li><i class="fas fa-circle text-xs mr-2 text-pink-400"></i>冗余设计</li>
                    </ul>
                </div>
            </div>
        </div>

        <!-- Background -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-6 section-title">CAP理论的提出背景</h2>
            
            <div class="quote-box">
                <p class="text-lg">
                    在互联网快速发展的过程中，系统架构从单体架构向分布式架构演进，这背后有着深刻的技术驱动力。
                </p>
            </div>

            <div class="space-y-6 mt-8">
                <div class="timeline-item">
                    <h4 class="font-bold text-lg mb-2">数据规模的爆炸性增长</h4>
                    <p class="text-gray-600">
                        随着互联网的普及和移动设备的广泛使用，数据生成量呈指数级增长。传统的集中式数据库已无法满足海量数据存储和处理的需求。
                    </p>
                </div>
                
                <div class="timeline-item">
                    <h4 class="font-bold text-lg mb-2">高可用性和容错性的需求</h4>
                    <p class="text-gray-600">
                        单体架构下，系统的可用性往往受到单点故障的严重影响。分布式系统通过将计算和存储分散到多个节点上，显著提高了系统的容错能力。
                    </p>
                </div>
                
                <div class="timeline-item">
                    <h4 class="font-bold text-lg mb-2">全球化应用的需求</h4>
                    <p class="text-gray-